package cn.thoughtworks.school.usercenter.entities.commands;

import cn.thoughtworks.school.usercenter.entities.User;
import lombok.*;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CreateUsersCommand {
    private String email;
    private String password;
    private String userName;
    private Long creatorId;

    public static List<User> buildUsers(List<CreateUsersCommand> createUsersCommands) {
        return createUsersCommands.stream()
            .map(CreateUsersCommand::build)
            .collect(Collectors.toList());
    }

    private static User build(CreateUsersCommand createUsersCommand) {
        return new User(createUsersCommand.userName, User.encryptPassword(createUsersCommand.password), createUsersCommand.email);
    }

}
